package org.belkodevelop.servlets.filter;

import java.io.IOException;
import javax.servlet.*;


public class EmptyFilter implements Filter  {

    private FilterConfig filterConfig;
    private String executeServlet = null;
    private boolean enable = true;
    
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
        this.executeServlet = filterConfig.getInitParameter("executeServlet");
        this.enable = filterConfig.getInitParameter("enable") != null && 
                filterConfig.getInitParameter("enable").equalsIgnoreCase("FALSE") ? false : true;
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        if (!enable) {
            filterChain.doFilter(request, response);
        } else {
            if (executeServlet != null) { 
                filterConfig.getServletContext().getNamedDispatcher(executeServlet).forward(request, response);
            }
        }  
    }

    @Override
    public void destroy() {
        
    }
    
}
